<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="评论管理" title-size="36" title-color="#333"></u-navbar>
        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#0F76BC"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item v-for="(item2, index2) in tabsList" :key="index2" class="swiperItem">
          <z-paging ref="paging" v-model="dataList[index2]" @query="queryList">
            <view class="comment-area">
              <view class="comment-box" v-for="(item, index1) in dataList[index2]" :key="index1">
                <view class="comment-info">
                  <view class="user-info">
                    <!-- <u-avatar :src="item." size="70"></u-avatar> -->
                    <view class="user">
                      用户
                      <p>{{ formatTime(item.createTime) }}</p>
                    </view>
                    <view class="user-rate">
                      <p>非常满意</p>
                      <u-rate :current="item.scores"></u-rate>
                    </view>
                  </view>
                </view>
                <view class="comment-content">
                  <view class="">
                    {{ item.content }}
                  </view>
                  <view class="comment-img">
                    <image :src="item.picUrls" mode=""></image>
                  </view>
                </view>
                <view class="reply" @click="onReply(item)"> 回复 </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>
    <u-popup v-model="show" mode="center" border-radius="15">
      <view class="popup-box">
        <view class="pop-title"> 评论回复 </view>
        <textarea
          class="inp-area"
          v-model="content"
          placeholder="输入回复内容"
          name=""
          id=""
          cols="30"
          rows="10"
        ></textarea>
        <view class="re-btn" @click="submit"> 确认回复 </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userId: '',
      show: false,
      countRate: 5,
      value: 5,
      stpe: 3,
      imgStyle: {
        width: '12rem'
      },
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部',
          status: 0
        },
        {
          name: '好评',
          status: 1
        },
        {
          name: '中评',
          status: 2
        },
        {
          name: '差评',
          status: 3
        }
      ],
      dataList: [[], [], [], []],
      check: '',
      content: ''
    }
  },
  onLoad() {
    this.userId = uni.getStorageSync('userInfo').id
    this.queryList()
  },
  computed: {
    formatTime() {
      return (e) => this.$utils.parseTime(e)
    }
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      this.scurrent = current
      this.current = current
      if (this.dataList[this.current].length == 0) {
        this.queryList()
      }
    },
    queryList(pageNo = 1, pageSize = 10) {
      this.$u
        .get('/app-api/construction/project-comment/page', {
          pageNo,
          pageSize,
          supplierUserId: this.userId,
          scoreType: this.tabsList[this.current].status
        })
        .then((res) => {
          this.$refs.paging[this.current].complete(res.data.list)
        })
    },
    initData(page, pageSize, status) {
      this.onOrderLoad(this.current, this.dataList, false)
    },
    onOrderLoad(current, orderList, loading) {
      if (loading) {
        this.$u.api.getOrderGroup({ filter_status: 1 }).then((res) => {
          console.log(res)
        })
        this.$refs.paging.reload()
      } else {
      }
    },
    onOrderDetail(item) {
      this.$utils.route({
        url: '/goods/group-order-details/group-order-details',
        params: {
          id: item.id
        }
      })
    },
    onReply(item) {
      this.check = item.id
      this.show = true
    },
    submit(e) {
      if (!this.content) {
        this.$u.toast('评论不能为空')
        return
      }
      this.$u.put('/app-api/construction/project-comment/reply', {
        id: this.check,
        content: this.content
      })
    },
    routeTo() {
      uni.navigateTo({
        url: '/goods/pre-goods-details/pre-goods-details'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
page {
  background: #eeeeef;
}

.content-tip {
  display: flex;
  height: 140rpx;
  background-color: #fff;
  margin: 20rpx 0;
  padding: 20rpx;
}

.mer-rate-left {
  flex: 3;
  text-align: center;
  view {
    font-size: 45rpx;
    font-weight: 700;
  }
  p {
    color: #666666;
  }
}

.mer-rate-right {
  flex: 7;
  margin-top: 20rpx;
  text {
    font: 35rpx;
  }
  .rate-tip {
    padding: 5rpx 10rpx;
    color: #ffac0e;
    background-color: #f5f0e6;
  }
}

.comment-area {
}

.comment-box {
  padding: 20rpx;
  background-color: #fff;
  margin-bottom: 10rpx;
}

.comment-top {
  overflow: auto;
}

.txt1 {
  font-size: 35rpx;
  float: left;
}

.txt2 {
  float: right;
  color: #7e7e5e;
}

.comment-info {
  overflow: auto;
  margin: 15rpx 0;
}
.comment-info-left {
  float: left;
  font-size: 30rpx;
  width: 45%;
}

.info-left-username {
  display: inline-block;
  vertical-align: top;
}

.comment-info-right {
  float: right;
}

.info-left-tx {
  width: 90rpx;
  height: 90rpx;
  border-radius: 90rpx;
}

.comment-img image {
  width: 200rpx;
  height: 200rpx;
  margin-right: 10rpx;
}

.goods-box {
  display: flex;
  align-items: center;
  padding: 15rpx 0;
  margin: 15rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
}
.goods-desc {
  line-height: 55rpx;
  font-size: 30rpx;
}

.goods-desc p {
  color: #999999;
  font-size: 26rpx;
}

.del-btn {
  display: inline-block;
  padding: 10rpx 20rpx;
  border: #999999 solid 2rpx;
  border-radius: 30rpx;
  color: #999999;
}

.user-info {
  display: flex;
  font-size: 24;
}

.user {
  flex: 1;
  margin-left: 10rpx;
}

.user p {
  color: #999999;
  font-size: 22rpx;
}

.user-rate {
  text-align: right;
}

.reply {
  width: 74rpx;
  padding: 8rpx 13rpx;
  margin-top: 15rpx;
  border-top: #ededed solid 2rpx;
  color: #fff;
  background-color: #0f76bc;
  font-size: 26rpx;
  border-radius: 10rpx;
}

.popup-box {
  padding: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.pop-title {
  text-align: center;
  font-size: 34rpx;
  padding: 20rpx 0;
}
.re-btn {
  width: 300rpx;
  height: 70rpx;
  border-radius: 35rpx;
  text-align: center;
  line-height: 80rpx;
  background-color: #0f76bc;
  color: #fff;
  margin: 15rpx 0;
}
.inp-area {
  background-color: #eeeeef;
  height: 300rpx;
}
</style>
